<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@page import="edu.ccut.saturn.component.SaturnData"%>
<html>
<head>
<title>修改密码</title>
<%@ include file="/extjs/include/all.jsp"%>
<script type="text/javascript" src="${pageContext.request.contextPath}/extjs/js/validate.js"></script>
<%
	SaturnData loginUser= (SaturnData)session.getAttribute("__SATURN_AUTORITY_USER__");
	String userId = loginUser.getString("id");
	String userName = loginUser.getString("username");
	String password = loginUser.getString("password");
%>
<script type="text/javascript">
Ext.onReady(function(){

  	Ext.QuickTips.init();   
 
  	//Ext.form.Field.prototype.msgTarget = 'side';  //在错误的表单项边上会出现一个红点，鼠标经过红点会有提示信息        
  
    var simple = new Ext.FormPanel({
    	id:'modifyPwdForm',
        labelWidth: 75, // label settings here cascade unless overridden
        frame:true,
        title: '修改密码',
        bodyStyle:'padding:5px 5px 0',
        width: 350,
        defaults: {width: 230},
        defaultType: 'textfield',
        items: [{
                fieldLabel: '登录名',
                name: 'userId',
                id: 'userId',
                value: '<%=userId%>',
                allowBlank:false,
                disabled:true
            },{
                fieldLabel: '姓名',
                name: 'userName',
                id: 'userName',
                allowBlank:false,
                value: '<%=userName%>',
                disabled:true
            },{
                fieldLabel: '原密码',
                name: 'originPwd',
                id: 'originPwd',
                allowBlank:false,
                blankText:'原密码不可为空',
                maxLength:16,
                inputType: 'password',
                vtype:'isNumberAlphaUnderline'
            }, {
                fieldLabel: '新密码',
                name: 'modifyPwd',
                id: 'modifyPwd',
                allowBlank:false,
                maxLength:16,
                blankText:'新密码不可为空',
                inputType: 'password',
                vtype:'isNumberAlphaUnderline'
            }, {
                fieldLabel: '确认密码',
                name: 'confirmPwd',
                id: 'confirmPwd',
                inputType: 'password',
                maxLength:16,
                allowBlank:false,
                blankText:'确认密码不可为空',
                vtype: 'repetition',
                repetition: { targetCmpId: 'modifyPwd' }
            }, {
                name: 'password',
                id: 'password',
                inputType: 'hidden',
                value:'<%=password%>'
            }
        ],

        buttons: [{
            text: '修改',
            vtype:'submit',
            handler: modifyPassword
        },{
            text: '重置',
            handler: cancel
        }]
    });
	
    simple.render('modifyPassword');
    
	document.getElementById('originPwd').maxLength = 16;
	document.getElementById('modifyPwd').maxLength = 16;
	document.getElementById('confirmPwd').maxLength = 16;
	
	function cancel(){
	
		Ext.getCmp('modifyPwdForm').form.reset(); 
	}

	function modifyPassword(){	 
		
		if(simple.form.isValid()){
		
			if (Ext.get('password').getValue() != Ext.get('originPwd').getValue()) { 
		
				Ext.MessageBox.alert('警告', '原密码错误，请重新输入！', originPwdFocus );
				return;
			}
			
			var form = simple.getForm().getEl().dom;   
	        form.action = '${pageContext.request.contextPath}/edu.ccut.saturn.authority.impl::/userModule/action/ModifyPasswd.action';   
	        form.target='_self';   
	        form.submit(); 
		}
	}
	
	function originPwdFocus(){
   		document.getElementById("originPwd").focus();
   		document.getElementById("originPwd").className = "x-form-text x-form-field x-form-invalid";
   	}
});
</script>
</head>
<body>
	<div id="modifyPassword"></div>
</body>
</html>